from selenium.webdriver.chrome.webdriver import WebDriver

from locators.sign_in import AuthenticationLocators
from pages.base import BasePage


class AuthorizationPage(BasePage):
    URL = "https://passport.yandex.ru/auth/welcome"

    def __init__(self, driver: WebDriver):
        super().__init__(driver)

    def input_password(self, passwd: str):
        password_field = self.find_element(AuthenticationLocators.PASSWORD)
        password_field.send_keys(passwd)
        submit_bt = self.find_element(AuthenticationLocators.SUBMIT)
        submit_bt.submit()
        self.wait_new_page("https://passport.yandex.ru/profile")

        return pages.ProfilePage(self.driver)

    def back_by_user_bt_click(self):
        found_user = self.find_element(AuthenticationLocators.CHOSEN_USER)
        found_user.click()

        self.wait_new_page(AuthenticationPage.URl_BY_BACK_BT)
        return AuthenticationPage(self.driver)

    def get_error_text(self):
        error_text = self.get_element_text(AuthenticationLocators.ERROR)
        return error_text
